home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / mach / hurd / mig-reply.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  2.4 KB  |  84 lines

  1. /* Copyright (C) 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <mach.h>
  20. #include <hurd/threadvar.h>
  21.  
  22. #define GETPORT \
  23.   mach_port_t *portloc = \
  24.     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
  25. #define reply_port (use_threadvar ? *portloc : global_reply_port)
  26.  
  27. static int use_threadvar;
  28. static mach_port_t global_reply_port;
  29.  
  30. /* These functions are called by MiG-generated code.  */
  31.  
  32. /* Called by MiG to get a reply port.  */
  33. mach_port_t
  34. __mig_get_reply_port (void)
  35. {
  36.   GETPORT;
  37.  
  38.   if (reply_port == MACH_PORT_NULL)
  39.     reply_port = __mach_reply_port ();
  40.  
  41.   return reply_port;
  42. }
  43.  
  44. /* Called by MiG to deallocate the reply port.  */
  45. void
  46. __mig_dealloc_reply_port (mach_port_t arg)
  47. {
  48.   mach_port_t port;
  49.  
  50.   GETPORT;
  51.  
  52.   port = reply_port;
  53.   reply_port = MACH_PORT_NULL;    /* So the mod_refs RPC won't use it.  */
  54.   __mach_port_mod_refs (__mach_task_self (), port,
  55.             MACH_PORT_RIGHT_RECEIVE, -1);
  56. }
  57.  
  58. /* Called by mig interfaces when done with a port.  Used to provide the
  59.    same interface as needed when a custom allocator is used.  */
  60. void
  61. __mig_put_reply_port(mach_port_t port)
  62. {
  63.   /* Do nothing.  */
  64. }
  65.  
  66.  
  67. /* Called at startup with STACK == NULL.  When per-thread variables are set
  68.    up, this is called again with STACK set to the new stack being switched
  69.    to, where per-thread variables should be set up.  */
  70. void
  71. __mig_init (void *stack)
  72. {
  73.   use_threadvar = stack != 0;
  74.  
  75.   if (use_threadvar)
  76.     {
  77.       /* Recycle the reply port used before multithreading was enabled.  */
  78.       mach_port_t *portloc = (mach_port_t *)
  79.     __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack);
  80.       *portloc = global_reply_port;
  81.       global_reply_port = MACH_PORT_NULL;
  82.     }
  83. }
  84.